package com.cloudminga.gui;


import com.globussoft.xml.SettingsXml;
//import com.pomblast.persistentlayer.User;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Gui_5.java
 *
 * Created on Dec 17, 2009, 1:29:39 PM
 */

/**
 *
 * @author jyoti
 */
public class Config_5_speed extends javax.swing.JDialog {

    /** Creates new form Gui_5 */
        Config_4_testresult configTestResult;

        int speed=128;
        int sliderVar=56;
        long sizeValue= 0;
        long estimeSeconds=0;
        int seconds=0,minutes=0,hours=0;
        String secondsStr,minutesStr,hoursStr;
        private String projectName="";
    //    public Config_5_speed(java.awt.Frame parent, boolean modal) {
        public Config_5_speed(java.awt.Frame parent, boolean modal,Config_4_testresult configTestResult) {
        super(parent, modal);
        Dimension dimension = new Dimension(600, 500);
        this.setDefaultCloseOperation(Config_5_speed.DISPOSE_ON_CLOSE);
         this.configTestResult=configTestResult;
        initComponents();
        projectName=SettingsXml.getProjectName();
        this.setTitle("Welcome to "+projectName+" Backup Wizard Configuration");
        jLabel2.setText("How fast "+projectName+" should  work ?");
        setSize(600, 500);
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        int x = (toolkit.getScreenSize().width - getWidth()) / 2;
        int y = (toolkit.getScreenSize().height - getHeight()) / 2;
        setResizable(true);
        setLocation(x, y);
        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        SettingsXml setting = new SettingsXml();
        sizeValue = ((setting.getSizeSpeed()) / 1024);
        estimeSeconds=sizeValue/(sliderSpeed.getValue());
     //   System.out.println("SizeSpeed "+ setting.getSizeSpeed());
      //  sliderSpeed.setMaximum(1024);
      //  sliderSpeed.setMinimum(128);
        //long files=setting.getInitFiles();
        this.label_initfiles.setText(Long.toString(setting.getInitFiles()));
        this.label_initsize.setText(setting.getInitSize());
         this.label_esttime.setText(timeFormat(estimeSeconds));
      

         try {
            /* code to set the look and feel according to the native operating system */
            
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          SwingUtilities.updateComponentTreeUI(this);

        } catch (Exception e) {
            System.out.println("Problem in setting look and feel");
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        nextSpeedButton = new javax.swing.JButton();
        cancelSpeedButton = new javax.swing.JButton();
        backSpeedButton = new javax.swing.JButton();
        sliderSpeed = new javax.swing.JSlider();
        FastCompLabel = new javax.swing.JLabel();
        QuickBackLabel = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        label_initsize = new javax.swing.JLabel();
        label_initfiles = new javax.swing.JLabel();
        label_esttime = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        label_Logo = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("");
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel2.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(51, 51, 255));
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 110, 220, -1));

        nextSpeedButton.setText("Next ");
        nextSpeedButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextSpeedButtonActionPerformed(evt);
            }
        });
        getContentPane().add(nextSpeedButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 400, -1, -1));

        cancelSpeedButton.setText("Cancel");
        cancelSpeedButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelSpeedButtonActionPerformed(evt);
            }
        });
        getContentPane().add(cancelSpeedButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 400, -1, -1));

        backSpeedButton.setText("Back");
        backSpeedButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backSpeedButtonActionPerformed(evt);
            }
        });
        getContentPane().add(backSpeedButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 400, -1, -1));

        sliderSpeed.setMaximum(1024);
        sliderSpeed.setMinimum(56);
        sliderSpeed.setPaintTicks(true);
        sliderSpeed.setSnapToTicks(true);
        sliderSpeed.setValue(256);
        sliderSpeed.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                sliderSpeedStateChanged(evt);
            }
        });
        getContentPane().add(sliderSpeed, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 160, 250, 40));

        FastCompLabel.setText("Faster Computer");
        getContentPane().add(FastCompLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 170, 90, -1));

        QuickBackLabel.setText("Quicker Backup");
        getContentPane().add(QuickBackLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 170, 100, -1));

        jLabel5.setText("Initial Backup set size:");
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 220, 120, -1));

        jLabel6.setText("Number of initial files to backup:");
        getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 240, 160, -1));

        jLabel7.setText("Estimated Time to complete:");
        getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 260, 160, -1));
        getContentPane().add(label_initsize, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 220, 60, -1));
        getContentPane().add(label_initfiles, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 240, 60, -1));
        getContentPane().add(label_esttime, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 260, 190, -1));

        jPanel1.setBackground(new java.awt.Color(204, 204, 204));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        label_Logo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/logo_2.png"))); // NOI18N
        jPanel1.add(label_Logo, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 10, 55, 55));

        jLabel1.setFont(new java.awt.Font("Arial", 0, 18));
        jLabel1.setForeground(new java.awt.Color(51, 51, 255));
        jLabel1.setText("Backup speed Selection");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, 210, -1));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 540, 80));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelSpeedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelSpeedButtonActionPerformed
        // TODO add your handling code here:
        this.dispose();
          
}//GEN-LAST:event_cancelSpeedButtonActionPerformed

    private void nextSpeedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextSpeedButtonActionPerformed
        // TODO add your handling code here:         
         SettingsXml setting=new SettingsXml();
         setting.setSpeed(speed);
     //    System.out.println("speed "+speed);
        //this.dispose();
         this.setVisible(false);
         new Config_6_complete(new javax.swing.JFrame(), true,this).setVisible(true);
}//GEN-LAST:event_nextSpeedButtonActionPerformed

    private void backSpeedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backSpeedButtonActionPerformed
        // TODO add your handling code here:
       //  this.dispose();
         this.setVisible(false);
         configTestResult.setVisible(true);
     //   new Config_4_testresult(new javax.swing.JFrame(), true).setVisible(true);
}//GEN-LAST:event_backSpeedButtonActionPerformed

    private void sliderSpeedStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_sliderSpeedStateChanged
        // TODO add your handling code here:

        sliderSpeed.setVisible(true);
        sliderVar=sliderSpeed.getValue();
        long estimeSeconds = (sizeValue / sliderVar);
        speed=sliderVar;
        this.label_esttime.setText(timeFormat(estimeSeconds));
      //  System.out.println("Slider speed time in sec "+timeFormat(estimeSeconds));
    }//GEN-LAST:event_sliderSpeedStateChanged

    public String timeFormat(long estime)
    {
     seconds = (int)(estime % 60);
     minutes = (int)((estime/60) % 60);
     hours = (int)((estime/3600) % 24);
     secondsStr = (seconds<10 ? "0" : "")+ seconds;
     minutesStr = (minutes<10 ? "0" : "")+ minutes;
     hoursStr = (hours<10 ? "0" : "")+ hours;
     return new String(hoursStr + " Hours " + minutesStr + " Minutes " + secondsStr + " Seconds ");
    }
    /**
    * @param args the command line arguments
    */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            @Override
//            public void run() {
//               Config_5_speed dialog = new Config_5_speed(new javax.swing.JFrame(), true);
//
//                dialog.addWindowListener(new java.awt.event.WindowAdapter()
//                {
//                    @Override
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel FastCompLabel;
    private javax.swing.JLabel QuickBackLabel;
    private javax.swing.JButton backSpeedButton;
    private javax.swing.JButton cancelSpeedButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel label_Logo;
    private javax.swing.JLabel label_esttime;
    private javax.swing.JLabel label_initfiles;
    private javax.swing.JLabel label_initsize;
    private javax.swing.JButton nextSpeedButton;
    public javax.swing.JSlider sliderSpeed;
    // End of variables declaration//GEN-END:variables

}
